#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        queue<int> q;
        for (auto& e : students) q.push(e);

        int i = 0, n = sandwiches.size();
        bool flag = true;
        while (i < n && flag)
        {
            int k = q.size();
            flag = false;
            while (k--)
            {
                int s = q.front(); q.pop();
                if (sandwiches[i] == s)
                {
                    flag = true;
                    break;
                }
                q.push(s);
            }
            ++i;
        }
        return q.size();
    }
};